//
//  MCNavVC.swift
//  MCBodyBuildingPro
//
//  Created by 然陈 on 2023/6/18.
//

import UIKit
import EachNavigationBar

class MCNavVC: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()
//        navigation.configuration.isEnabled = true
//        navigation.configuration.largeTitle.displayMode = .never
//        navigation.configuration.backItem = Configuration.BackItem(style: .image(UIImage(named: "nav_back")))
        
//        guard let interactionGes = interactivePopGestureRecognizer else { return }
//        guard let targetView = interactionGes.view else { return }
//        guard let internalTargets = interactionGes.value(forKeyPath: "targets") as? [NSObject] else { return }
//        guard let internalTarget = internalTargets.first?.value(forKey: "target") else { return }
//        let action = Selector(("handleNavigationTransition:"))

//        let fullScreenGesture = UIPanGestureRecognizer(target: internalTarget, action: action)
//        fullScreenGesture.delegate = self
//        targetView.addGestureRecognizer(fullScreenGesture)
//        interactionGes.isEnabled = false
    }
    

    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
            if viewControllers.count > 1 {
                viewController.hidesBottomBarWhenPushed = true
//                if let vc = viewControllers {
//                    let backButton = UIButton()
//                    backButton.setImage(UIImage(named: "nav_back"), for: .normal)
//                    backButton.addTarget(self, action: #selector(clickBack), for: .touchUpInside)
//                viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: backButton)
//                }
            }
            super.pushViewController(viewController, animated: animated)
        }
    
    @objc func clickBack() {
        popViewController(animated: true)
    }
    
}
//
//extension MCNavVC {
//    
//    override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
//        let isLeftToRight = UIApplication.shared.userInterfaceLayoutDirection == .leftToRight
//        guard let ges = gestureRecognizer as? UIPanGestureRecognizer else { return true }
//        if ges.translation(in: gestureRecognizer.view).x * (isLeftToRight ? 1 : -1) <= 0
//            || disablePopGesture {
//            return false
//        }
//        return viewControllers.count != 1;
//    }
//}
//
//
//enum BaseNavigationBarStyle {
//    case theme
//    case clear
//    case white
//}
//
//extension UINavigationController {
//    
//    private struct AssociatedKeys {
//        static var disablePopGesture: Void?
//    }
//    
//    var disablePopGesture: Bool {
//        get {
//            return objc_getAssociatedObject(self, &AssociatedKeys.disablePopGesture) as? Bool ?? false
//        }
//        set {
//            objc_setAssociatedObject(self, &AssociatedKeys.disablePopGesture, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
//        }
//    }
//    
//    func barStyle(_ style: BaseNavigationBarStyle) {
//        switch style {
//        case .theme:
//            navigationBar.barStyle = .black
//            navigationBar.setBackgroundImage(UIImage(named: "nav_bg"), for: .default)
//            navigationBar.shadowImage = UIImage()
//        case .clear:
//            navigationBar.barStyle = .black
//            navigationBar.setBackgroundImage(UIImage(), for: .default)
//            navigationBar.shadowImage = UIImage()
//        case .white:
//            navigationBar.barStyle = .default
////            navigationBar.setBackgroundImage(, for: .default)
//            navigationBar.shadowImage = nil
//        }
//    }
//}
